<template>
  <div>
    个人信息
    id是{{id}} {{name}}
      <el-table style="width: 100%" border :data="list">
      <template v-for="(item,index) in tableHead">
        <el-table-column :prop="item.prop" :label="item.name" :key="index"></el-table-column>
      </template>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[2, 4, 8, 10]"
        :page-size="2"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "UserList",
  props: ["id", "name"],

  data() {
    return {
      total: 0,
      pages: 0,
      current: 1,
      size: 2,
      list: [],
      tableHead: [
        {
          name: "编号",
          prop: "id"
        },
        {
          name: "用户名",
          prop: "userName"
        },
        {
          name: "密码",
          prop: "password"
        }
      ]
    };
  },
  /* 进入之前*/
  beforeRouteEnter: (to, from, next) => {
    console.log("准备进入 userprofile page");
    next(vm => {
        vm.getData();
    });
  },
  beforeRouteLeave: (to, from, next) => {
    next();
  },
  methods: {
    handleSizeChange: function(val) {
      //改变页面大小时 重置到第一页
      this.size = val;
      this.current=1;
      this.getData();
    },
    handleCurrentChange: function(val) {
      this.current = val;
      this.getData();
    },
    getData: function() {
      let params = {
          size: this.size,
          current: this.current
              };
      this.$axiosGet("/api-user/list", params)
        .then(result => {
           let data = result.data.data;
          this.list = data.records;
          this.size = data.size;
          this.current = data.current;
          this.pages = data.pages;
          this.total = data.total;
        })
       
    }
  }
};
</script>

<style scoped>
</style>
